//////////////////////////////////////////////////////////////////////////////////////////////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	File			:	"Game.h
//	Authors			:	Jake Castillo,
//	Project			:	Project Aetheryte
//	Date Modified	:	8/6/2013
//	Purpose			:	Runs the functionality of the game.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////////////////////////////////


#pragma once

// Header Dependencies
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <vector>
#include "../SGD Wrappers/SGD_String.h"
#include <signal.h>

//***********************************************************
// Forward Class Declarations
class CSGD_Direct3D;
class CSGD_DirectInput;
class CSGD_TextureManager;
class CSGD_XAudio2;
class AnimationSystem;

class IGameState;
class CPlayer;
class CWeapon;

class Font;

struct Resolution
{
	int width, height;
};

//***********************************************************
// CGame class
//	- singleton - only ONE object
//	- handles the game logic
class CGame
{
public:
	//*******************************************************
	// SINGLETON
	//	- global access point
	static CGame* GetInstance( void );
	static void	  DeleteInstance( void );


	//*******************************************************
	// CGame Interface:
	void Initialize( HWND hWnd, HINSTANCE hInstance,
					 int nWidth, int nHeight,
					 bool bWindowed );
	bool Main( void );
	void Terminate( void );

	//*******************************************************
	// Window Accessors (no mutators):
	int			GetScreenWidth	( void ) const	{	return	m_nScreenWidth;		}
	int			GetScreenHeight	( void ) const	{	return	m_nScreenHeight;	}
	bool		GetIsWindowed	( void ) const	{	return	m_bIsWindowed;		}
	HWND		GetHWND() const					{	return  pHWND;				}
	HINSTANCE	GetHInstance() const			{	return	pInstance;			}

	// Volume Accessors
	float	GetBGVolume		( void ) const	{	return	masterBGVolume;		}
	float	GetSFXVolume	( void ) const	{	return	masterSFXVolume;	}

	// Volume Mutators
	void	SetBGVolume		( float f ) 	{	masterBGVolume	= f;	}
	void	SetSFXVolume	( float f ) 	{	masterSFXVolume	= f;	}

	// Game State Machine
	void	ChangeState( IGameState* pNewState );
	IGameState* GetPrevState()	{ return m_pPrevState; }

	// Languages
	void LoadStrings();

	//const TCHAR* GetCursor()		{ return Cursor.str().c_str();	}
	//const TCHAR* GetExit()			{ return ExitStr.str().c_str();	}

	std::vector<Font*>			vFonts;
	enum Language {English = 0, Eorzean = 1, Swedish = 2 };

	unsigned int	GetLanguage()				{	return language;	}
	void			SetLanguage(unsigned int i)	
	{	
		language = i;	
		LoadStrings();
	}

	void Pause();

	bool IsLoaded() const		{ return Loaded;	}
	void SetLoaded(bool b)		{ Loaded = b;		}
	int	 LoadID()	const		{ return loadID;	}
	void SetLoadID(int b)		{ loadID = b;		}

	void StartWrappers( HWND hWnd, HINSTANCE hInstance,
					 int nWidth, int nHeight,
					 bool bWindowed );

	void CreateFonts();

	Font* GetTitleFont() const	{ return Title;		}
	Font* GetMenuFont() const	{ return Menu;		}

	Resolution  GetResolution() const	{ return res;		}
	void  SetResolution(Resolution r)	{ res = r;			}

	void SetWindowed(bool b);
	void HideCursor(bool b);
	
private:
	//*******************************************************
	// SINGLETON
	//	- private static pointer to the singleton object
	//	- prevents multiple instances from being created
	static CGame* s_pInstance;

	CGame( void );
	~CGame( void );
	CGame( const CGame& );					// copy ctor
	CGame& operator= ( const CGame& );		// assignment op


	//*******************************************************
	// Helper Functions:
	bool Input( void );
	void Update( void );
	void Render( void );

	//*******************************************************
	// Window Attributes
	int						m_nScreenWidth;
	int						m_nScreenHeight;
	bool					m_bIsWindowed;

	HWND					pHWND;
	HINSTANCE				pInstance;

	//*******************************************************
	// Wrappers
	CSGD_Direct3D*			m_pD3D;
	CSGD_DirectInput*		m_pDI;
	CSGD_TextureManager*	m_pTM;
	CSGD_XAudio2*			m_pXA;
	AnimationSystem*		m_pAS;

	//*******************************************************
	// Current Time (in milliseconds)
	DWORD					m_dwCurrTime;

	//*******************************************************
	// Current Game State
	IGameState*				m_pCurrState;
	IGameState*				m_pPrevState;

	//*******************************************************
	// Master Volumes
	float					masterBGVolume;
	float					masterSFXVolume;

	// Language
	unsigned int			language;
	
	bool	Paused;
	bool	Loaded;
	bool	hideCursor;

	Resolution res;

	int		loadID;

	Font*	Title;
	Font*	Menu;

	//TOSTRINGSTREAM Cursor;
	//TOSTRINGSTREAM ExitStr;
};

